﻿using System;
using DevExpress.XtraEditors;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;

namespace Kiosk
{
    public partial class frmAyarlar : XtraForm
    {
        public frmAyarlar()
        {
            InitializeComponent();
            RepositoryItemComboBox riCombo = new RepositoryItemComboBox();
            riCombo.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            foreach (string item in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                riCombo.Items.Add(item);
            }
            this.editorRow1.Properties.RowEdit = riCombo;
        }

        private void frmAyarlar_Load(object sender, EventArgs e)
        {
            FillGrid(vGridControl1);
        }

        private void FillGrid(DevExpress.XtraVerticalGrid.VGridControl vgrid)
        {
            for (int i = 1; i < vgrid.Rows.Count; i++)
            {
                if (!string.IsNullOrEmpty(vgrid.Rows[i].Properties.FieldName))
                {
                    switch (vgrid.Rows[i].Properties.UnboundType)
                    {
                        case DevExpress.Data.UnboundColumnType.Boolean:
                            vgrid.Rows[i].Properties.Value = Convert.ToBoolean(Program.Session[(Settings)Enum.Parse(typeof(Settings), vgrid.Rows[i].Properties.FieldName)]);
                            break;
                        case DevExpress.Data.UnboundColumnType.DateTime:
                            vgrid.Rows[i].Properties.Value = Convert.ToDateTime(Program.Session[(Settings)Enum.Parse(typeof(Settings), vgrid.Rows[i].Properties.FieldName)]);
                            break;
                        case DevExpress.Data.UnboundColumnType.Decimal:
                            vgrid.Rows[i].Properties.Value = Convert.ToDecimal(Program.Session[(Settings)Enum.Parse(typeof(Settings), vgrid.Rows[i].Properties.FieldName)]);
                            break;
                        case DevExpress.Data.UnboundColumnType.Integer:
                            vgrid.Rows[i].Properties.Value = Convert.ToInt32(Program.Session[(Settings)Enum.Parse(typeof(Settings), vgrid.Rows[i].Properties.FieldName)]);
                            break;
                        case DevExpress.Data.UnboundColumnType.String:
                            vgrid.Rows[i].Properties.Value = Convert.ToString(Program.Session[(Settings)Enum.Parse(typeof(Settings), vgrid.Rows[i].Properties.FieldName)]);
                            break;
                        default:
                            vgrid.Rows[i].Properties.Value = Program.Session[(Settings)Enum.Parse(typeof(Settings), vgrid.Rows[i].Properties.FieldName)];
                            break;
                    }
                }
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < vGridControl1.Rows.Count; i++)
            {
                if (vGridControl1.Rows[i].Properties.Value != null)
                    Program.Session[((Settings)Enum.Parse(typeof(Settings), vGridControl1.Rows[i].Properties.FieldName))] = vGridControl1.Rows[i].Properties.Value.ToString();
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                vGridControl1.FocusedRow.Properties.Value = dlg.FileName;
            }
        }

        private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                vGridControl1.FocusedRow.Properties.Value = dlg.FileName;
            }
        }
    }
}
